//
//  WithDrawListTableViewCell.swift
//  kxf
//
//  Created by Mac on 2024/3/12.
//

import Foundation
import UIKit

class WithDrawListTableViewCell: UITableViewCell {
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .COLOR_LIGHT_GREY
        self.selectionStyle = .none
        
        initUI()
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(8)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var orderIconImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "withdraw_order_icon")
        
        return img
    }()
    lazy var titleLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        lab.text = "订单号"
        
        return lab
    }()
    lazy var orderLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
    lazy var moneyLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 18, weight: .bold)
        
        return lab
    }()
    lazy var statusLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        
        return lab
    }()
}

extension WithDrawListTableViewCell{
    func updateUI(dict:NSDictionary) {
        orderLabel.text = "\(dict["outTradeId"]as? String ?? "")"
        timeLabel.text = "时间：\(Date().timestampToDate(timestamp: TimeInterval((dict["createTime"]as? Int ?? 0)/1000),format: "yyyy-MM-dd HH:mm:ss"))"
        moneyLabel.text = "¥ \(dict["amount"]as? Double ?? 0.00)"
        
        if dict["state"]as? Int ?? -1 == 0 {
            statusLabel.text = "提现成功"
        }else if dict["state"]as? Int ?? -1 == 3 {
            statusLabel.text = "处理中"
        }else if dict["state"]as? Int ?? -1 == 1 {
            statusLabel.text = "失败"
        }else if dict["state"]as? Int ?? -1 == 7 {
            statusLabel.text = "待审核"
        }
        
    }
}
extension WithDrawListTableViewCell{
    func initUI() {
        contentView.addSubview(whiteView)
        whiteView.addSubview(orderIconImgView)
        whiteView.addSubview(titleLabel)
        whiteView.addSubview(orderLabel)
        whiteView.addSubview(moneyLabel)
        whiteView.addSubview(timeLabel)
        whiteView.addSubview(statusLabel)
        
        setConstrait()
    }
    func setConstrait() {
        whiteView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(10))
            make.width.equalTo(kFitWidth(343))
            make.height.equalTo(kFitWidth(106))
        }
        orderIconImgView.snp.makeConstraints { make in
            make.left.top.equalTo(kFitWidth(13))
            make.width.height.equalTo(kFitWidth(22))
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(41))
            make.centerY.lessThanOrEqualTo(orderIconImgView)
        }
        orderLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.top.equalTo(kFitWidth(46))
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.top.equalTo(kFitWidth(75))
        }
        moneyLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-12))
            make.top.equalTo(kFitWidth(32))
        }
        statusLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-13))
            make.top.equalTo(kFitWidth(75))
        }
    }
}
